package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.bumptech.glide.Glide;
import com.foamtrace.photopicker.PhotoPickerActivity;
import com.foamtrace.photopicker.PhotoPreviewActivity;
import com.foamtrace.photopicker.SelectModel;
import com.foamtrace.photopicker.intent.PhotoPickerIntent;
import com.foamtrace.photopicker.intent.PhotoPreviewIntent;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.orhanobut.logger.Logger;
import com.qiniu.android.common.Zone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.BusinessqfcatReq;
import com.ydkj.a37e_mall.Classes.Model.Request.StoreDataReq;
import com.ydkj.a37e_mall.Classes.Model.Request.StorethumbnailReq;
import com.ydkj.a37e_mall.Classes.Model.Request.StroreimgReq;
import com.ydkj.a37e_mall.Classes.Model.Request.TokenReq;
import com.ydkj.a37e_mall.Classes.Model.Request.UpdateStoreReq;
import com.ydkj.a37e_mall.Classes.Model.Response.StoreDataResp;
import com.ydkj.a37e_mall.Classes.Model.Response.TokenResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.Rsa;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.MyGridView;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;

import static com.loopj.android.http.AsyncHttpClient.log;


/**
 * Created by Administrator on 2017/1/16.
 * 我的门店--》门店管理
 */

public class StoreManagementActivity extends BaseActivity implements View.OnClickListener, OnGetGeoCoderResultListener {
    private Activity mActivity;
    private MyApplication myApplication;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private EditText et_store_message_name, et_store_message_telephone, et_store_message_adress, et_store_message_banknum,
            et_store_details_introduce;
    private ImageView back;
    private TextView tv_open_credentials_num, address, tv_store_thumbnail_num, type, banktype;
    private LinearLayout lly_address;
    private RelativeLayout rly_submit, rly_address, rly_type, rly_banktype;
    private ScrollView scrollView;
    private MapView mapView;
    private BaiduMap mBaiduMap = null;
    private GeoCoder mSearch = null; // 搜索模块，也可去掉地图模块独立使用
    private BitmapDescriptor mCurrentMarker;

    private MyLocationConfiguration.LocationMode mCurrentMode;
    private LocationClient mLocClient; // 定位相关
    public MyLocationListenner myListener = new MyLocationListenner();
    boolean isFirstLoc = true;// 是否首次定位

    private static final int REQUEST_CAMERA_CODE = 11;
    private static final int REQUEST_PREVIEW_CODE = 22;

    private MyGridView gridview_store_thumbnail;//门店缩略图
    private ArrayList<String> imagePaths = null;
    private StoreimgAdapter storeimgAdapter;
    private List<StroreimgReq> stroreimglist;
    private boolean is_choose_picture = false;//已经选择了一张门店缩略图


    private MyGridView gridview_store_details;//门店详情
    private ArrayList<String> stroredetailsPaths;
    private StorethumbnailAdapter storethumbnailAdapter;
    private List<StorethumbnailReq> stroredetailslist;


    private MyGridView gridview_business_qualification;//营业资质
    private ArrayList<String> businessqfcatPaths;
    private BusinessqfcatAdapter businessqfcatAdapter;
    private List<BusinessqfcatReq> businessqfcatlist;

    private List<String> path;
    private int columnWidth, selectimgcode;
    private int seekbarnum = 0;
    private long timenum = 1;
    private String storeid;//门店Id

    //用来传七牛的字符串用“，” 隔开
    private String thumbstr;
    private String albumstr;
    private String licensestr;
    private List<String> thumblist;
    private List<String> albumlist;
    private List<String> licenslist;

    private int thumbnail_index = 0, store_detail_index = 0, business_fcat_index = 0;


    private List<StoreDataResp.ResultEntity.DataEntity> storedatalist;

    String lat, lng;//获取商家列表经纬度

    private String latitude, longitude;//根据输入地址获取到的经纬度
    private String addressname;

    private String type_id = "";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.store_management);
        mActivity = this;
        init();
//        initWindow();


        GetStoreData();//获取门店数据

        intentview();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);

    }

    private void init() {
        initmapview();
        myApplication = MyApplication.getInstance();
        log.e("ssss", "ssss==>" + myApplication.getProvince3());
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        path = new ArrayList<>();
        imagePaths = new ArrayList<>();
        stroredetailsPaths = new ArrayList<>();
        businessqfcatPaths = new ArrayList<>();

        thumblist = new ArrayList<>();
        albumlist = new ArrayList<>();
        licenslist = new ArrayList<>();

        stroreimglist = new ArrayList<>();
        stroredetailslist = new ArrayList<>();
        businessqfcatlist = new ArrayList<>();

        gridview_store_thumbnail = (MyGridView) mActivity.findViewById(R.id.gridview_store_thumbnail);
        gridview_store_details = (MyGridView) mActivity.findViewById(R.id.gridview_store_details);
        gridview_business_qualification = (MyGridView) mActivity.findViewById(R.id.gridview_business_qualification);

        storedatalist = new ArrayList<StoreDataResp.ResultEntity.DataEntity>();

        et_store_message_name = (EditText) mActivity.findViewById(R.id.et_store_message_name);
        et_store_message_telephone = (EditText) mActivity.findViewById(R.id.et_store_message_telephone);
        et_store_message_adress = (EditText) mActivity.findViewById(R.id.et_store_message_adress);
        et_store_details_introduce = (EditText) mActivity.findViewById(R.id.et_store_details_introduce);
        et_store_message_banknum = (EditText) mActivity.findViewById(R.id.et_store_message_banknum);
        back = (ImageView) mActivity.findViewById(R.id.img_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        banktype = (TextView) mActivity.findViewById(R.id.banktype);
        tv_store_thumbnail_num = (TextView) mActivity.findViewById(R.id.tv_store_thumbnail_num);
        tv_open_credentials_num = (TextView) mActivity.findViewById(R.id.tv_open_credentials_num);//门店缩略图个数
        address = (TextView) mActivity.findViewById(R.id.address);
        type = (TextView) mActivity.findViewById(R.id.type);

        rly_address = (RelativeLayout) mActivity.findViewById(R.id.rly_address);
        rly_submit = (RelativeLayout) mActivity.findViewById(R.id.rly_submit);
        rly_type = (RelativeLayout) mActivity.findViewById(R.id.rly_type);
        rly_banktype = (RelativeLayout) mActivity.findViewById(R.id.rly_banktype);
        et_store_message_adress.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int arg1, KeyEvent keyEvent) {
                if (arg1 == EditorInfo.IME_ACTION_DONE) {
                    if (myApplication.getCity3() == null) {
                        mSearch.geocode(new GeoCodeOption().city(storedatalist.get(0).getCity()).address(et_store_message_adress.getText().toString()));
                        log.e("ssss", "1111111111==>" + storedatalist.get(0).getCity());
                    } else {
                        mSearch.geocode(new GeoCodeOption().city(myApplication.getCity3()).address(et_store_message_adress.getText().toString()));
                        log.e("ssss", "222222222==>" + myApplication.getCity3());

                    }
                    return true;
                }
                return false;
            }
        });


        rly_address.setOnClickListener(this);
        rly_submit.setOnClickListener(this);
        rly_type.setOnClickListener(this);
        rly_banktype.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rly_address://获取地址
                myApplication.setStorename3(et_store_message_name.getText().toString());
                myApplication.setMobile3(et_store_message_telephone.getText().toString());
                myApplication.setAddress3(et_store_message_adress.getText().toString());
                myApplication.setDescription3(et_store_details_introduce.getText().toString());

                myApplication.setStroreimglist(stroreimglist);
                myApplication.setStroredetailslist(stroredetailslist);
                myApplication.setBusinessqfcatlist(businessqfcatlist);


                myApplication.setStroreimgnum3(imagePaths.size());
                myApplication.setStroredetailsnum3(stroredetailsPaths.size());
                myApplication.setBusinessqfcatnum3(businessqfcatPaths.size());
                myApplication.setIntent_code(5);
                Intent intent1 = new Intent(mActivity, ChooseAddressProvince.class);
                startActivity(intent1);

                break;
            case R.id.rly_submit://提交
                if (type_id.equals("")) {
                    CommonUtil.showToast(mActivity, "请选择门店类型");
                    return;
                }
                if (et_store_message_name.getText().toString().equals("")) {
                    CommonUtil.showToast(mActivity, "门店名称不能为空");
                    return;
                }
                if (et_store_message_telephone.getText().toString().equals("")) {
                    CommonUtil.showToast(mActivity, "联系电话不能为空");
                    return;
                }
                if (et_store_message_adress.getText().toString().equals("")) {
                    CommonUtil.showToast(mActivity, "地址不能为空");
                    return;
                }
                if (is_choose_picture == false) {
                    CommonUtil.showToast(mActivity, "请至少添加一张门店缩略图片");
                    return;
                }
                if (et_store_details_introduce.getText().toString().equals("")) {
                    CommonUtil.showToast(mActivity, "请介绍一下您的店");
                    return;
                }
                if (stroredetailslist.size() < 2) {
                    CommonUtil.showToast(mActivity, "请至少添加一张门店详情图片");
                    return;
                }
                if (businessqfcatlist.size() < 2) {
                    CommonUtil.showToast(mActivity, "请至少添加一张营业资质图片");
                    return;
                }

                CustomProgressDialog.createDialog(mActivity).show();

                thumbnail_index = 0;
                store_detail_index = 0;
                business_fcat_index = 0;
                thumblist.clear();
                albumlist.clear();
                licenslist.clear();
                for (String str : imagePaths) {
                    if (str.substring(0, 4).equals("http")) {
                        String result = str.substring(str.lastIndexOf('/') + 1);
                        thumblist.add(result);
                        thumbstr = CommonUtil.listToString(thumblist, ',');
                        thumbnail_index++;
                    }
                }
                for (String str : stroredetailsPaths) {
                    if (str.substring(0, 4).equals("http")) {
                        String result = str.substring(str.lastIndexOf('/') + 1);
                        albumlist.add(result);
                        albumstr = CommonUtil.listToString(albumlist, ',');
                        store_detail_index++;
                    }
                }
                for (String str : businessqfcatPaths) {
                    if (str.substring(0, 4).equals("http")) {
                        String result = str.substring(str.lastIndexOf('/') + 1);
                        licenslist.add(result);
                        licensestr = CommonUtil.listToString(licenslist, ',');
                        business_fcat_index++;
                    }
                }

                UploadPicture();

                break;
            case R.id.rly_type:
                Intent intent = new Intent(mActivity, StoreTypeActivity.class);
                intent.putExtra("code", 2);
                startActivityForResult(intent, 1);
                break;

            case R.id.rly_banktype:
                Intent intent2 = new Intent(mActivity, BankcarActivity.class);
                intent2.putExtra("code", 3);
                startActivityForResult(intent2, 3);

                break;
        }
    }

    private void UploadPicture() {
        if (imagePaths.size() > 0) {
            if (thumbnail_index != imagePaths.size()) {//上传门店缩略图
                Log.e("123456", "门店缩略图  thumbnail_index==>" + thumbnail_index + "   imagePaths.size()==" + imagePaths.size());

                Logger.e("ssss", "门店缩略图img_UploadPicture ==>" + imagePaths.get(thumbnail_index));
//                        GetthumbToken(imagePaths.get(i), "thumb" + imagePaths.get(i).substring(imagePaths.get(i).lastIndexOf("/"), imagePaths.get(i).length()));

                String photo_name = myApplication.getChannelID() +
                        imagePaths.get(thumbnail_index).substring(imagePaths.get(thumbnail_index).length() - 18, imagePaths.get(thumbnail_index).length()) + getTime();

                Log.e("ssss", "门店缩略图img_photo_name==>" + photo_name);


                String foot = imagePaths.get(thumbnail_index).substring(imagePaths.get(thumbnail_index).length() - 4, imagePaths.get(thumbnail_index).length());
                String photo_path = CommonUtil.createRandom(false, 5) + foot;//md5加密（alia+名称+时间戳）


                Log.e("ssss", "门店缩略图img_photo_path ==>" + photo_path);

                GetthumbToken(imagePaths.get(thumbnail_index), photo_path);
            } else {
                if (stroredetailsPaths.size() > 0) {
                    if (store_detail_index != stroredetailsPaths.size()) {//上传门店详情
                        Log.e("123456", "门店详情  store_detail_index==>" + store_detail_index + "   stroredetailsPaths.size()==" + stroredetailsPaths.size());
                        Logger.e("ssss", "门店详情img_UploadPicture ==>" + stroredetailsPaths.get(store_detail_index));
//                        Logger.e("ssss", "门店详情img2 ==>" +  stroredetailsPaths.get(i).substring(stroredetailsPaths.get(i).length()-19, stroredetailsPaths.get(i).length()));
//                        Logger.e("ssss", "门店详情img3 ==>" +  stroredetailsPaths.get(i).substring(stroredetailsPaths.get(i).lastIndexOf("/"), stroredetailsPaths.get(i).length()));
//                        Log.e("ssss", "门店详情img 33==>" + stroredetailsPaths.get(i).charAt(stroredetailsPaths.get(i).length()-19));
                        String photo_name = myApplication.getChannelID() +
                                stroredetailsPaths.get(store_detail_index).substring(stroredetailsPaths.get(store_detail_index).length() - 18, stroredetailsPaths.get(store_detail_index).length()) + getTime();
                        Log.e("ssss", "门店详情img_photo_name==>" + photo_name);
                        String foot = stroredetailsPaths.get(store_detail_index).substring(stroredetailsPaths.get(store_detail_index).length() - 4, stroredetailsPaths.get(store_detail_index).length());
                        String photo_path = CommonUtil.createRandom(false, 5) + foot;//md5加密
                        Log.e("ssss", "门店详情img_photo_path ==>" + photo_path);

                        GetalbumToken(stroredetailsPaths.get(store_detail_index), photo_path);
                    } else {
                        if (businessqfcatPaths.size() > 0) {
                            if (business_fcat_index != businessqfcatPaths.size()) {//上传营业资质
                                Log.e("123456", "营业资质  business_fcat_index==>" + business_fcat_index + "   businessqfcatPaths.size()==" + businessqfcatPaths.size());
                                Logger.e("ssss", "营业资质img_UploadPicture ==>" + businessqfcatPaths.get(business_fcat_index));
//                        GetlicenseToken(businessqfcatPaths.get(i), "album" + businessqfcatPaths.get(i).substring(businessqfcatPaths.get(i).lastIndexOf("/"), businessqfcatPaths.get(i).length()));
                                String photo_name = myApplication.getChannelID() +
                                        businessqfcatPaths.get(business_fcat_index).substring(businessqfcatPaths.get(business_fcat_index).length() - 18, businessqfcatPaths.get(business_fcat_index).length()) + getTime();
                                Log.e("ssss", "营业资质img_photo_name==>" + photo_name);
                                String foot = businessqfcatPaths.get(business_fcat_index).substring(businessqfcatPaths.get(business_fcat_index).length() - 4, businessqfcatPaths.get(business_fcat_index).length());
                                String photo_path = CommonUtil.createRandom(false, 5) + foot;//md5加密
                                Log.e("ssss", "营业资质img_photo_path ==>" + photo_path);
                                GetlicenseToken(businessqfcatPaths.get(business_fcat_index), photo_path);


                            } else {
                                Log.e("url", "上传完成");
                                CustomProgressDialog.Dismiss();
                                updateStore();//修改门店信息
                            }

                        }
                    }
                }

            }
        }
    }

    //用来接收选择地址后传过来的参数
    private void intentview() {
//        if (myApplication.getStorename3() != null) {
//            et_store_message_name.setText(myApplication.getStorename3());
//        }
//        if (myApplication.getMobile3() != null) {
//            et_store_message_telephone.setText(myApplication.getMobile3());
//        }
//        if (myApplication.getAddress3() != null) {
//            et_store_message_adress.setText(myApplication.getAddress3());
//        }
//        if (myApplication.getDescription3() != null) {
//            et_store_details_introduce.setText(myApplication.getDescription3());
//        }
        log.e("ssss", "address==>" + myApplication.getProvince3() + myApplication.getCity3() + myApplication.getArea3() + myApplication.getLocation3());
        if (myApplication.getProvince3() != null || myApplication.getCity3() != null || myApplication.getArea3() != null || myApplication.getLocation3() != null) {
            address.setText(myApplication.getProvince3() + myApplication.getCity3() + myApplication.getArea3() + myApplication.getLocation3());
        }

    }

    //获取我的门店数据
    private void GetStoreData() {
        CustomProgressDialog.createDialog(mActivity).show();
        StoreDataReq req = new StoreDataReq();
        req.setUuid(myApplication.getDataEntity().getUuid());

        for (int i = 0; i < myApplication.getDataEntity().getStore_id().size(); i++) {
            storeid = myApplication.getDataEntity().getStore_id().get(i) + "";
            log.e("ssss1", "storeid==>" + storeid);
        }
        req.setId(storeid);

        RequestParams params = new RequestParams();
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("ssss", "Store_response==>" + response);
                if (errno.equals("000")) {
                    StoreDataResp resp = GsonImpl.get().toObject(response.toString(), StoreDataResp.class);
                    storedatalist.clear();
                    storedatalist.addAll(resp.getResult().getData());
                    et_store_message_name.setText(storedatalist.get(0).getName());
                    et_store_message_telephone.setText(storedatalist.get(0).getMobile());
                    et_store_message_adress.setText(storedatalist.get(0).getAddress());
                    et_store_details_introduce.setText(storedatalist.get(0).getDetail());
                    address.setText(storedatalist.get(0).getProvince() + storedatalist.get(0).getCity() + storedatalist.get(0).getArea() + storedatalist.get(0).getLocation());
                    type.setText(storedatalist.get(0).getIndustry());
                    type_id = storedatalist.get(0).getIndustry_id();
                    addressname = storedatalist.get(0).getAddress();
                    lat = storedatalist.get(0).getLat();
                    lng = storedatalist.get(0).getLng();

                    //根据经纬度搜索
                    LatLng ptCenter = new LatLng((Float.valueOf(storedatalist.get(0).getLat() + "")), (Float.valueOf(storedatalist.get(0).getLng() + "")));
//                    LatLng ptCenter = new LatLng(24.533576, 118.166432);
                    mSearch.reverseGeoCode(new ReverseGeoCodeOption()
                            .location(ptCenter));


                    //门店缩略图
                    stroreimglist.clear();
                    StroreimgReq req = new StroreimgReq();
                    imagePaths.add(storedatalist.get(0).getThumb());
                    req.setImgpath(storedatalist.get(0).getThumb());
                    stroreimglist.add(req);
                    storeimgAdapter = new StoreimgAdapter(stroreimglist);
                    gridview_store_thumbnail.setAdapter(storeimgAdapter);
                    storeimgAdapter.notifyDataSetChanged();
                    if (imagePaths.size() > 0) {
                        is_choose_picture = true;
                    }

                    //门店详情
                    stroredetailslist.clear();
                    for (int i = 0; i < storedatalist.get(0).getAlbum().size(); i++) {
                        stroredetailsPaths.add(storedatalist.get(0).getAlbum().get(i));
                        StorethumbnailReq req1 = new StorethumbnailReq();
                        req1.setImgpath(storedatalist.get(0).getAlbum().get(i));
                        stroredetailslist.add(req1);
                    }
                    storethumbnailAdapter = new StorethumbnailAdapter(stroredetailslist);
                    gridview_store_details.setAdapter(storethumbnailAdapter);
                    storethumbnailAdapter.notifyDataSetChanged();


                    //营业资质
                    businessqfcatlist.clear();
                    for (int i = 0; i < storedatalist.get(0).getLicense().size(); i++) {
                        businessqfcatPaths.add(storedatalist.get(0).getLicense().get(i));
                        BusinessqfcatReq req2 = new BusinessqfcatReq();
                        req2.setImgpath(storedatalist.get(0).getLicense().get(i));

                        businessqfcatlist.add(req2);
                    }

                    businessqfcatAdapter = new BusinessqfcatAdapter(businessqfcatlist);
                    gridview_business_qualification.setAdapter(businessqfcatAdapter);
                    businessqfcatAdapter.notifyDataSetChanged();


                    initstoreThumbnail();//门店缩略图 girdview
                    initstoreDetails();//门店详情 girdview
                    initbusinessqualification();//营业资质 girdview
                } else {
                    CommonUtil.showToast(mActivity, errmsg);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }


    //修改门店
    private void updateStore() {
//        CustomProgressDialog.createDialog(mActivity).show();
        UpdateStoreReq req = new UpdateStoreReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setStats("");
        req.setType(type_id);
        req.setName(et_store_message_name.getText().toString());
        req.setContact(myApplication.getDataEntity().getNickname());
        req.setMobile(et_store_message_telephone.getText().toString());
        req.setAddress(et_store_message_adress.getText().toString());
        if (myApplication.getProvince_id3() == null) {
            req.setProvince_id(storedatalist.get(0).getProvince_id());
        } else {
            req.setProvince_id(myApplication.getProvince_id3());
        }

        if (myApplication.getCity_id3() == null) {
            req.setCity_id(storedatalist.get(0).getCity_id());
        } else {
            req.setCity_id(myApplication.getCity_id3());
        }

        if (myApplication.getArea_id3() == null) {
            req.setArea_id(storedatalist.get(0).getArea_id());
        } else {
            req.setArea_id(myApplication.getArea_id3());
        }

        if (myApplication.getLocation_id3() == null) {
            req.setLocation_id(storedatalist.get(0).getLocation_id());
        } else {
            req.setLocation_id(myApplication.getLocation_id3());
        }

        if (latitude == null && longitude == null) {
            req.setLng(lng);
            req.setLat(lat);
        } else {
            req.setLng(CommonUtil.roundDouble(Double.parseDouble(longitude), 6) + "");
            req.setLat(CommonUtil.roundDouble(Double.parseDouble(latitude), 6) + "");

        }

        req.setLicense(licensestr);
        req.setThumb(thumbstr);
        req.setAlbum(albumstr);
        req.setDescription(et_store_details_introduce.getText().toString());


        RequestParams params = new RequestParams();

        for (int i = 0; i < myApplication.getDataEntity().getStore_id().size(); i++) {
        }
        storeid = myApplication.getDataEntity().getStore_id().get(0) + "";

//        params.put("store_id", storeid);
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Log.e("url", "store_id==" + storeid + "    token==" + sharedPreferencesUtil.getAccessToken());

        Log.e("url", "secret==" + req.getSecret());

        Log.e("url", "url==" + Const.COMMON_ADDRESS + req.urlString() + storeid);
        String url = Const.COMMON_ADDRESS + req.urlString() + storeid;
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.put(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "onSuccess_response==" + response);
                if (errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    finish();

                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                Log.e("url", "statusCode==" + statusCode + "  responseString==" + responseString);
                CommonUtil.showToast(mActivity, "网络连接失败");
                Log.e("url", "onFailure_responseString==" + responseString);
            }
        });


    }

    //获取门店缩略图的Token
    private void GetthumbToken(final String data, final String key) {
        TokenReq req = new TokenReq();
        req.setType("store_thumb");
        req.setKey(key);
        try {
            String source = req.getstring();
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(source);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String url = Const.COMMON_ADDRESS + req.urlString();
        params.put("secret", secret);

        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);

                Log.e("url", "门店缩略图response==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");

                if (errno.equals("000")) {
                    TokenResp resp = GsonImpl.get().toObject(response.toString(), TokenResp.class);
                    PostQiniu(data, key, resp.getResult().getUptoken(), 1);

                }
                if (!errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
            }
        });
    }

    private void PostQiniu(String data, String key, String token, final int code) {
//        Log.e("ssss", "data==>" + data);
//        Log.e("ssss", "key==>" + key);
//        Log.e("ssss", "token==>" + token);

        //http上传,指定zone的具体区域
        Configuration config = new Configuration.Builder().zone(Zone.zone2).build();
        UploadManager uploadManager = new UploadManager(config);
//        data = <File对象、或 文件路径、或 字节数组>
//        String key = <指定七牛服务上的文件名，或 null>;
//        String token = <从服务端SDK获取>;
        uploadManager.put(data, key, token,
                new UpCompletionHandler() {
                    @Override
                    public void complete(String key, ResponseInfo info, JSONObject res) {
                        //res包含hash、key等信息，具体字段取决于上传策略的设置
                        if (info.isOK()) {
                            switch (code) {

                                case 1://门店缩略图
                                    thumblist.add(key);
                                    thumbstr = CommonUtil.listToString(thumblist, ',');
                                    Log.e(ssss, "thumbstr==>" + thumbstr);
                                    thumbnail_index++;
                                    break;
                                case 2://门店营业执照
                                    albumlist.add(key);
                                    albumstr = CommonUtil.listToString(albumlist, ',');
                                    Log.e(ssss, "albumstr==>" + albumstr);
                                    business_fcat_index++;
                                    break;
                                case 3://门店相册
                                    licenslist.add(key);
                                    licensestr = CommonUtil.listToString(licenslist, ',');
                                    Log.e(ssss, "licensestr==>" + licensestr);
                                    store_detail_index++;
                                    break;
                            }

                            if (thumblist.size() == stroreimglist.size() && albumlist.size() + 1 == businessqfcatlist.size() && licenslist.size() + 1 == stroredetailslist.size()) {
                                log.e("ssss", "全部上传成功");
                                CustomProgressDialog.Dismiss();
                                updateStore();//修改门店信息

                            } else {
                                UploadPicture();
                            }
                        } else {

                            Log.e("ssss", "上次失败");
                            //如果失败，这里可以把info信息上报自己的服务器，便于后面分析上传错误原因
                        }
//                        Log.e("ssss", key + ",\r\n " + info + ",\r\n " + res);
                    }
                }, null);

    }

    //获取门店营业执照的Token
    private void GetlicenseToken(final String data, final String key) {
        //        CustomProgressDialog.createDialog(mActivity).show();
        TokenReq req = new TokenReq();
        req.setType("store_license");
        req.setKey(key);
        try {
//            log.e("ssss", "req.getSecret()===>" + req.getstring());
            String source = req.getstring();
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(source);
//            log.e("ssss", "secret===>" + secret);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String url = Const.COMMON_ADDRESS + req.urlString();
        params.put("secret", secret);

        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);

                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");

                if (errno.equals("000")) {
                    TokenResp resp = GsonImpl.get().toObject(response.toString(), TokenResp.class);
                    PostQiniu(data, key, resp.getResult().getUptoken(), 2);

                }
                if (!errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
//                log.e("ssss", "statusCode==>" + statusCode);
            }
        });
    }

    //获取门店相册的Token
    private void GetalbumToken(final String data, final String key) {
        //        CustomProgressDialog.createDialog(mActivity).show();
        TokenReq req = new TokenReq();
        req.setType("store_album");
        req.setKey(key);
        try {
//            log.e("ssss", "req.getSecret()===>" + req.getstring());
            String source = req.getstring();
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(source);
//            log.e("ssss", "secret===>" + secret);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String url = Const.COMMON_ADDRESS + req.urlString();
        params.put("secret", secret);

        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);

                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");

                if (errno.equals("000")) {
                    TokenResp resp = GsonImpl.get().toObject(response.toString(), TokenResp.class);
                    PostQiniu(data, key, resp.getResult().getUptoken(), 3);

                }
                if (!errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
//                log.e("ssss", "statusCode==>" + statusCode);
            }
        });
    }

    //门店缩略图
    private void initstoreThumbnail() {
        int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
        cols = cols < 3 ? 3 : cols;
        int screenWidth = getResources().getDisplayMetrics().widthPixels;
        int columnSpace = getResources().getDimensionPixelOffset(R.dimen.space_size);
        columnWidth = (screenWidth - columnSpace * (cols - 1)) / cols;
//        gridview_store_thumbnail.setNumColumns(cols);


//        StroreimgReq req = new StroreimgReq();
//        req.setImgpath("");
//        stroreimglist.add(req);
//
//        storeimgAdapter = new StoreimgAdapter(stroreimglist);
//        gridview_store_thumbnail.setAdapter(storeimgAdapter);

        //
        gridview_store_thumbnail.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectimgcode = 1;
                if (imagePaths.size() == 1) {
                    Log.e("ssss", "11111");
                    PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                    intent.setCurrentItem(position);
                    intent.setPhotoPaths(imagePaths);
                    startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                } else {
                    Log.e("ssss", "2222");

                    if (position == parent.getChildCount() - 1) {
                        Log.e("ssss", "点击加号====");
                        PhotoPickerIntent intent = new PhotoPickerIntent(mActivity);
                        intent.setSelectModel(SelectModel.MULTI);
                        intent.setShowCarema(true); // 是否显示拍照
                        intent.setMaxTotal(1); // 最多选择照片数量，默认为9
                        intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                        startActivityForResult(intent, REQUEST_CAMERA_CODE);
                    } else {
                        Log.e("ssss", "点击已添加的图片");
                        PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                        intent.setCurrentItem(position);
                        intent.setPhotoPaths(imagePaths);
                        startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                    }
                }

            }
        });
    }

    //门店详情
    private void initstoreDetails() {
//        gridview_store_thumbnail.setNumColumns(cols);

        StorethumbnailReq req = new StorethumbnailReq();
        req.setImgpath("");
        stroredetailslist.add(req);

        storethumbnailAdapter = new StorethumbnailAdapter(stroredetailslist);
        gridview_store_details.setAdapter(storethumbnailAdapter);

        //
        gridview_store_details.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectimgcode = 2;
                if (stroredetailsPaths.size() == 9) {
                    PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                    intent.setCurrentItem(position);
                    intent.setPhotoPaths(stroredetailsPaths);
                    startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                } else {
                    if (position == parent.getChildCount() - 1) {
                        Log.e("ssss", "点击加号++++");

                        PhotoPickerIntent intent = new PhotoPickerIntent(mActivity);
                        intent.setSelectModel(SelectModel.MULTI);
                        intent.setShowCarema(true); // 是否显示拍照
                        intent.setMaxTotal(9); // 最多选择照片数量，默认为9
                        intent.setSelectedPaths(stroredetailsPaths); // 已选中的照片地址， 用于回显选中状态
                        startActivityForResult(intent, REQUEST_CAMERA_CODE);
                    } else {
                        PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                        intent.setCurrentItem(position);
                        intent.setPhotoPaths(stroredetailsPaths);
                        startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                    }
                }

            }
        });
    }

    //营业资质
    private void initbusinessqualification() {


//        gridview_store_thumbnail.setNumColumns(cols);

        BusinessqfcatReq req = new BusinessqfcatReq();
        req.setImgpath("");
        businessqfcatlist.add(req);

        businessqfcatAdapter = new BusinessqfcatAdapter(businessqfcatlist);
        gridview_business_qualification.setAdapter(businessqfcatAdapter);

        //
        gridview_business_qualification.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectimgcode = 3;
                if (businessqfcatPaths.size() == 9) {
                    PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                    intent.setCurrentItem(position);
                    intent.setPhotoPaths(businessqfcatPaths);
                    startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                } else {
                    if (position == parent.getChildCount() - 1) {
                        Log.e("ssss", "点击加号++++");

                        PhotoPickerIntent intent = new PhotoPickerIntent(mActivity);
                        intent.setSelectModel(SelectModel.MULTI);
                        intent.setShowCarema(true); // 是否显示拍照
                        intent.setMaxTotal(9); // 最多选择照片数量，默认为9
                        intent.setSelectedPaths(businessqfcatPaths); // 已选中的照片地址， 用于回显选中状态
                        startActivityForResult(intent, REQUEST_CAMERA_CODE);
                    } else {
                        PhotoPreviewIntent intent = new PhotoPreviewIntent(mActivity);
                        intent.setCurrentItem(position);
                        intent.setPhotoPaths(businessqfcatPaths);
                        startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                    }
                }

            }
        });
    }

    // 地图定位初始化
    private void initmapview() {
        scrollView = (ScrollView) mActivity.findViewById(R.id.scrollView);

        mapView = (MapView) mActivity.findViewById(R.id.mapview);
        mBaiduMap = mapView.getMap();

        // 初始化搜索模块，注册事件监听
        mSearch = GeoCoder.newInstance();
        mSearch.setOnGetGeoCodeResultListener(this);
//        //定位相关
//        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
//        // 开启定位图层
//        mBaiduMap.setMyLocationEnabled(true);
//        // 定位初始化
//        mLocClient = new LocationClient(mActivity);
//
//        mLocClient.registerLocationListener(myListener);
//        LocationClientOption option = new LocationClientOption();
//        option.setOpenGps(true);// 打开gps
//        option.setCoorType("bd09ll"); // 设置坐标类型
//        option.setScanSpan(30000);
//        mLocClient.setLocOption(option);
//        mLocClient.start();

        //解决 mapview和scrollview的滑动冲突
        View v = mapView.getChildAt(0);//这个view实际上就是我们看见的绘制在表面的地图图层
        v.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    scrollView.requestDisallowInterceptTouchEvent(false);
                } else {
                    scrollView.requestDisallowInterceptTouchEvent(true);
                }
                return false;
            }
        });

        //百度地图手势移动的时候，图标也跟着移动
        mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() {

            @Override
            public void onMapStatusChangeStart(MapStatus arg0) {
                //手势操作地图，设置地图状态等操作导致地图状态开始改变。
            }

            @Override
            public void onMapStatusChangeFinish(MapStatus arg0) {
                //地图状态改变结束
//                searchLl.setVisibility(View.GONE);
                mBaiduMap.clear();
                mBaiduMap.addOverlay(new MarkerOptions().position(arg0.target)
                        .icon(mCurrentMarker));
                // 反Geo搜索
                mSearch.reverseGeoCode(new ReverseGeoCodeOption()
                        .location(arg0.target));
                Log.e("url", "百度地图的反Geo搜索==" + arg0.target);

                latitude = (arg0.target.latitude) + "";
                longitude = (arg0.target.longitude) + "";

//                // 初始化MKSearch
//                mMKSearch = new MKSearch();
//                mMKSearch.init(mapManager, new MySearchListener());
//                // 查询该经纬度值所对应的地址位置信息
//                mSearch.reverseGeocode(new GeoPoint(latitude, longitude));
                mSearch.setOnGetGeoCodeResultListener(listener);

            }

            @Override
            public void onMapStatusChange(MapStatus arg0) {
                //地图状态变化中
            }
        });

        mCurrentMarker = BitmapDescriptorFactory
                .fromResource(R.mipmap.ic_edit_location_red_400_36dp);
        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
        mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
                mCurrentMode, true, mCurrentMarker));

    }

    OnGetGeoCoderResultListener listener = new OnGetGeoCoderResultListener() {
        public void onGetGeoCodeResult(GeoCodeResult result) {
            if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                //没有检索到结果
                Log.e("url", "没有检索到结果==" + result);
            }
            //获取地理编码结果
            Log.e("url", "获取地理编码结果==" + result.getAddress());
        }

        @Override
        public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
            if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                //没有找到检索结果
                Log.e("url", "没有检索到结果==" + result);
            }
            //获取反向地理编码结果
            Log.e("url", "获取反向地理编码结果==" + result.getAddress());
            et_store_message_adress.setText(result.getAddress());
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                // 选择照片
                case REQUEST_CAMERA_CODE:
                    switch (selectimgcode) {
                        case 1: //门店缩略图

                            loadAdpater(data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT));
                            break;
                        case 2://门店详情
                            loadAdpater(data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT));

                            break;
                        case 3://营业资质
                            loadAdpater(data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT));

                            break;

                    }
                    break;
                // 预览
                case REQUEST_PREVIEW_CODE:

                    switch (selectimgcode) {
                        case 1://门店缩略图
                            loadAdpater(data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT));
                            break;
                        case 2://门店详情
                            loadAdpater(data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT));

                            break;
                        case 3://营业资质
                            loadAdpater(data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT));

                            break;
                        case 4://身份证照片
                            break;
                    }
                    break;

                case 1:
                    type.setText(data.getExtras().getString("type"));
                    type_id = data.getExtras().getString("type_id");
                    log.e("ssss", "type_id==>" + type_id);
                    break;
                case 3:

                    banktype.setText(data.getExtras().getString("name"));
                    log.e("ssss", "type_id==>" + type_id);
                    break;
//                // 调用相机拍照
//                case ImageCaptureManager.REQUEST_TAKE_PHOTO:
//                    if (captureManager.getCurrentPhotoPath() != null) {
//                        captureManager.galleryAddPic();
//
//                        ArrayList<String> paths = new ArrayList<>();
//                        paths.add(captureManager.getCurrentPhotoPath());
//                        loadAdpater(paths);
//                    }
//                    break;

            }
        }
    }

    //图片添加 ++++
    private void loadAdpater(List<String> paths) {
        switch (selectimgcode) {
            case 1://门店缩略图
                if (imagePaths == null) {
                    imagePaths = new ArrayList<>();
                }
                imagePaths.clear();
                imagePaths.addAll(paths);
                if (stroreimglist == null) {
                    stroreimglist = new ArrayList<StroreimgReq>();
                }
                stroreimglist.clear();
                for (int i = 0; i < imagePaths.size(); i++) {
                    StroreimgReq strorereq = new StroreimgReq();
                    Log.e("ssss", "门店缩略图img ==>" + imagePaths.get(i));

                    strorereq.setImgpath(imagePaths.get(i));
                    stroreimglist.add(strorereq);
                }
                if (stroreimglist.size() < 9) {
                    StroreimgReq req = new StroreimgReq();
                    req.setImgpath("");
                    stroreimglist.add(req);
                }

                if (storeimgAdapter == null) {
                    storeimgAdapter = new StoreimgAdapter(stroreimglist);
                    gridview_store_thumbnail.setAdapter(storeimgAdapter);

                } else {
                    if (stroreimglist.size() == 2) {//如果图片选好了，就隐藏加号
                        stroreimglist.remove(1);
                        is_choose_picture = true;
                    }
                    storeimgAdapter.notifyDataSetChanged();
                }
                break;
            case 2://门店详情
                if (stroredetailsPaths == null) {
                    stroredetailsPaths = new ArrayList<String>();
                }
                stroredetailsPaths.clear();
                stroredetailsPaths.addAll(paths);

                if (stroredetailslist == null) {
                    stroredetailslist = new ArrayList<StorethumbnailReq>();
                }
                stroredetailslist.clear();
                for (int i = 0; i < stroredetailsPaths.size(); i++) {
                    StorethumbnailReq storethumbnailReq = new StorethumbnailReq();

                    // uuid=fcefrgasth1rped9&type=4&name=哆啦A梦门店&contact=张晓波&mobile=15559088225&address=西湖公园
                    // &province_id=16068&city_id=16572&area_id=1187&location_id=15244&lat=24.533576&lng=118.166432
                    // &license=thumb/Screenshot_2016-07-16-21-09-18_com.tencent.qqlive_1468674594544.jpg
                    // &thumb=album/IMG_20161211_180718.jpg
                    // &album=license/Screenshot_2016-07-16-21-09-18_com.tencent.qqlive_1468674594544.jpg
                    // &description=福建省泉州市丰泽区北峰街道西湖公

                    //IMG_20161211_180718.jpg(15)
                    //qqlive_1468674594544.jpg(15)
                    //  3cb605b98687054a7633733bc09d050f

                    Log.e("ssss", "门店详情img ==>" + stroredetailsPaths.get(i));

                    storethumbnailReq.setImgpath(stroredetailsPaths.get(i));
                    stroredetailslist.add(storethumbnailReq);
                }
                if (stroredetailslist.size() < 9) {
                    StorethumbnailReq req = new StorethumbnailReq();
                    req.setImgpath("");
                    stroredetailslist.add(req);
                }

                if (storethumbnailAdapter == null) {
                    storethumbnailAdapter = new StorethumbnailAdapter(stroredetailslist);
                    gridview_store_thumbnail.setAdapter(storethumbnailAdapter);
                    Log.e("ssss", "2222");

                } else {
                    Log.e("ssss", "33333");

                    storethumbnailAdapter.notifyDataSetChanged();
                }
                break;


            case 3://营业资质
                if (businessqfcatPaths == null) {
                    businessqfcatPaths = new ArrayList<String>();
                }
                businessqfcatPaths.clear();
                businessqfcatPaths.addAll(paths);

                if (businessqfcatlist == null) {
                    businessqfcatlist = new ArrayList<BusinessqfcatReq>();
                }
                businessqfcatlist.clear();
                for (int i = 0; i < businessqfcatPaths.size(); i++) {
                    BusinessqfcatReq businessqfcatReq = new BusinessqfcatReq();
                    Log.e("ssss", "营业资质img ==>" + businessqfcatPaths.get(i));

                    businessqfcatReq.setImgpath(businessqfcatPaths.get(i));
                    businessqfcatlist.add(businessqfcatReq);
                }
                if (businessqfcatlist.size() < 9) {
                    BusinessqfcatReq req = new BusinessqfcatReq();
                    req.setImgpath("");
                    businessqfcatlist.add(req);
                }

                if (businessqfcatAdapter == null) {
                    businessqfcatAdapter = new BusinessqfcatAdapter(businessqfcatlist);
                    gridview_business_qualification.setAdapter(businessqfcatAdapter);
                    Log.e("ssss", "444");

                } else {
                    Log.e("ssss", "5555");

                    businessqfcatAdapter.notifyDataSetChanged();
                }
                break;
        }

    }


    @Override
    public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
        if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(mActivity, "抱歉，未能找到结果", Toast.LENGTH_LONG)
                    .show();
            return;
        }
        log.e("ssss", "11111==" + result.getLocation());
        mBaiduMap.clear();

        mBaiduMap.addOverlay(new MarkerOptions().position(result.getLocation()).icon(BitmapDescriptorFactory.fromResource(R.mipmap.location)));

        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(result.getLocation()));
    }

    @Override
    public void onGetGeoCodeResult(GeoCodeResult result) {
        if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(mActivity, "抱歉，未能找到结果", Toast.LENGTH_LONG)
                    .show();

            return;
        }
        log.e("ssss", "22222");
        mBaiduMap.clear();
        mBaiduMap.addOverlay(new MarkerOptions().position(result.getLocation())
                .icon(BitmapDescriptorFactory
                        .fromResource(R.mipmap.location)));
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(result
                .getLocation()));
        String strInfo = String.format("纬度：%f 经度：%f",
                result.getLocation().latitude, result.getLocation().longitude);
        Toast.makeText(mActivity, strInfo, Toast.LENGTH_LONG).show();
        latitude = result.getLocation().latitude + "";
        longitude = result.getLocation().longitude + "";


    }

    //门店缩略图Adapter  ++++
    private class StoreimgAdapter extends BaseAdapter {
        private List<StroreimgReq> listUrls;

        public StoreimgAdapter(List<StroreimgReq> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            return listUrls.size();
        }

        @Override
        public StroreimgReq getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            StoreimgAdapter.ViewHolder vh = null;

            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.store_img_list, null);
                vh = new StoreimgAdapter.ViewHolder();
                vh.imageView = (ImageView) convertView.findViewById(R.id.imageView11);
                // 重置ImageView宽高
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth - 10, columnWidth - 10);
                vh.imageView.setLayoutParams(params);
                convertView.setTag(vh);
            } else {

                vh = (StoreimgAdapter.ViewHolder) convertView.getTag();
            }
            if (imagePaths.size() < 1) {
                tv_store_thumbnail_num.setText("门店缩略图(" + "0" + "张)");
            } else {
                tv_store_thumbnail_num.setText("门店缩略图(" + imagePaths.size() + "张)");

            }

            if (getItem(position).getImgpath().length() > 0) {
//                Log.e("ssss", "11111");
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);
            } else {
//                Log.e("ssss", "加号存在");
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.img_add)
                        .error(R.mipmap.img_add)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);

//                if (listUrls.size() == 9) {
//
//                    if (position == 10) {
//                        vh.imageView.setVisibility(View.GONE);
//                    }
//                } else {
//                    Log.e("ssss", "加号存在");
//                    vh.imageView.setImageResource(R.mipmap.img_add);
//                }


            }
            return convertView;

        }

        private class ViewHolder {
            ImageView imageView;
        }
    }


    //门店详情 Adapter   -----
    private class StorethumbnailAdapter extends BaseAdapter {
        private List<StorethumbnailReq> listUrls;

        public StorethumbnailAdapter(List<StorethumbnailReq> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            return listUrls.size();
        }

        @Override
        public StorethumbnailReq getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;

            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.store_img_list, null);
                vh = new ViewHolder();
                vh.imageView = (ImageView) convertView.findViewById(R.id.imageView11);
                // 重置ImageView宽高
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth - 10, columnWidth - 10);
                vh.imageView.setLayoutParams(params);
                convertView.setTag(vh);
            } else {

                vh = (ViewHolder) convertView.getTag();
            }

            if (getItem(position).getImgpath().length() > 0) {
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);
            } else {
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.img_add)
                        .error(R.mipmap.img_add)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);
            }
            return convertView;

        }

        private class ViewHolder {
            ImageView imageView;
        }
    }


    //营业资质 Adapter +++++
    private class BusinessqfcatAdapter extends BaseAdapter {
        private List<BusinessqfcatReq> listUrls;

        public BusinessqfcatAdapter(List<BusinessqfcatReq> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            return listUrls.size();
        }

        @Override
        public BusinessqfcatReq getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;

            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.store_img_list, null);
                vh = new ViewHolder();
                vh.imageView = (ImageView) convertView.findViewById(R.id.imageView11);
                // 重置ImageView宽高
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth - 10, columnWidth - 10);
                vh.imageView.setLayoutParams(params);
                convertView.setTag(vh);
            } else {

                vh = (ViewHolder) convertView.getTag();
            }

            if (getItem(position).getImgpath().length() > 0) {
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);
            } else {
                Glide.with(mActivity)
                        .load(new File(getItem(position).getImgpath()))
                        .placeholder(R.mipmap.img_add)
                        .error(R.mipmap.img_add)
                        .centerCrop()
                        .crossFade()
                        .into(vh.imageView);
            }
            return convertView;
        }

        private class ViewHolder {
            ImageView imageView;
        }
    }

    /**
     * 定位SDK监听函数
     */
    public class MyLocationListenner implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mapView == null)
                return;
            MyLocationData locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
//            Log.e("ssss", "经度==》" + location.getLatitude());
//            Log.e("ssss", "纬度==》" + location.getLongitude());
            mBaiduMap.setMyLocationData(locData);
            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
                MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
                mBaiduMap.animateMapStatus(u);
            }
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        log.e("ssss", "onResume");
        intentview();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 退出时销毁定位
//        mLocClient.stop();
        // 关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
    }

    /**
     * 获取时间戳
     */
    public String getTime() {

        Timestamp cyrrent_time = new Timestamp(System.currentTimeMillis());//获取系统当前时间
        System.out.println("cyrrent_time-->" + cyrrent_time);//返回结果精确到毫秒。

        return cyrrent_time + "";
    }


}
